package com.fieldchain.ex.fa100.utils.string.watcher;

import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;

import com.fieldchain.ex.fa100.inter.StringCallBack;
import com.fieldchain.ex.fa100.utils.string.NumberFormate;

/**
 * Created by biyunlong
 * Email: 1225198434@qq.com
 * Data:  2018/9/18
 */
public class C2CTextWatcher {
    private double price=0;
    public void setPrice(double price){
        this.price=price;
    }

    public C2CTextWatcher(EditText et, final  StringCallBack callBack) {
        listener(et, new StringCallBack() {
            @Override
            public void message(String msg) {
                float num=Long.parseLong(msg);
                callBack.message(NumberFormate.m5(price*num));
            }
        });
    }
    public void listener(EditText et, final StringCallBack callBack){
        et.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                if(editable.length()==0){
                    callBack.message(0+"");
                }else{
                    callBack.message(editable.toString());
                }

            }
        });
    }
}
